package com.mobilebsc.app;

import java.util.List;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.example.mobilebsc.R;
import com.mobilebsc.datamanager.IDataReadyListener;
import com.mobilebsc.datamanager.PerspectivesDataManager;
import com.mobilebsc.datatype.Perspective;

public class ConfigurationActivity extends Activity implements IDataReadyListener {
	
	PerspectivesDataManager pdm = new PerspectivesDataManager(this);
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		
		super.onCreate(savedInstanceState);
		
		setContentView(R.layout.activity_configuration);

        TextView tvBC = (TextView) findViewById(R.id.textViewBC);
        tvBC.setText("Home > Settings >");
	}
	
	public void onClick_btn_Configuration_Cancel(View view) {
		startActivity(new Intent(this, MainActivity.class));
	}
	
	public void onClick_btn_LoadData(View v){
        
        ConnectivityManager connMgr = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
        if (networkInfo != null && networkInfo.isConnected()) {
        	
        	Toast.makeText(getApplicationContext(), "Network available.", Toast.LENGTH_LONG).show();
        	
        	pdm.getAll();
        	
        } else {
        	Toast.makeText(getApplicationContext(), "Network not available.", Toast.LENGTH_LONG).show();
        }
    }

	@Override
	public void dataReady() {
		List<Perspective> list = pdm.loadAll();
		
		if(list.get(0) != null) {
			Toast.makeText(getApplicationContext(), "Server access successful.", Toast.LENGTH_LONG).show();
		} else {
			Toast.makeText(getApplicationContext(), "Server access not successful.", Toast.LENGTH_LONG).show();
		}		
	}
}